#include<iostream.h>
#include<ctype.h>
#include<conio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>

// converts hexadecimal value to decimal and perform the operation
// specified by the char c with the decimal value n and the result
// of operation is obtained from the input string(alias).
void hex(char in[],char c,int &n)
{
  int i,j,len,factor=1;
  int val=0,tmp;
  char ret[10],ch;

  len=strlen(in);

  for(i=len-1;i>=0;i--)
  {
   ch=toupper(in[i]);
   switch(ch)
    {
     case'0':
     case'1':
     case'2':
     case'3':
     case'4':
     case'5':
     case'6':
     case'7':
     case'8':
     case'9':  tmp=(ch-48)*factor; break;

     case'A':
     case'B':
     case'C':
     case'D':
     case'E':
     case'F': tmp=(ch-55)*factor;  break;
    }//switch

   val+=tmp;
   factor*=16;
  }//for

  switch(c)
   {
    case '+': val+=n;   break;
    case '-': val-=n;   break;
    case ' ': break;
   }//switch

   n=val;
   itoa(val,ret,16);
   strcpy(in,ret);
}// end of hex


